/**
 * Copyright (c) 2018-2019 PoleStar Studio. All Rights Reserved. <br>
 * Use is subject to license terms.<br>
 * <p>
 * 在此处填写文件说明
 */
package springjdbc;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 填写功能简述.
 * <p>填写详细说明.<br>
 * @version v1.0
 * @author lianzuozheng
 * @date 2019/4/29 -下午 04:39 
 */
@Repository
public class AccountDaoImpl implements AccountDao {
    @Resource
    private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public int addAccount(Account account) {
        String sql="insert into account(username,balance)"+
                "values(?,?)";
        Object[] args=new Object[]{
          account.getUsername(),
          account.getBalance()
        };
        int rows = this.jdbcTemplate.update(sql,args);
        if (rows>0) {
            System.out.println("插入成功");
        }else{
            System.out.println("插入失败");
        }
        return 0;
    }

    @Override
    public int updateAccount(Account account) {
        return 0;
    }

    @Override
    public int deleteAccount(Integer id) {
        return 0;
    }

    @Override
    public Account findAccountById(Integer id) {
        String sql ="select * from account where id=?";
        RowMapper<Account> RowMapper = new BeanPropertyRowMapper<>(Account.class);
        return this.jdbcTemplate.queryForObject(sql, RowMapper,id);
    }

    @Override
    public List<Account> findAllAccount() {

        return null;
    }

}
